﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Sms.Model.V20160927;
using Newtonsoft.Json;

namespace Common.Helper
{
    public class SMSHelper
    {
        public static string sendUrl = "https://sms.aliyuncs.com/?Action=SingleSendSms&Format=JSON&SignName=亿车汇&TemplateCode={0}&RecNum={1}&ParamString={2}";

        public static bool SendVcode(string vcode,string phonenum)
        {
            var _vcode = JsonConvert.SerializeObject(new VCode(){code = vcode});
            var sendurl = string.Format(sendUrl, "SMS_56690059", phonenum, WebHelper.UrlEncode(_vcode));

            IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "0Phv3FKEO5KpbHpU", "WbQGomfMLmWUybT8Nqszv21SS5kejF");
            IAcsClient client = new DefaultAcsClient(profile);
            SingleSendSmsRequest request = new SingleSendSmsRequest();
            try
            {
                request.SignName = "亿车汇";
                request.TemplateCode = "SMS_56690059";
                request.RecNum = phonenum;
                request.ParamString = _vcode;
                SingleSendSmsResponse httpResponse = client.GetAcsResponse(request);
                return true;
            }
            catch
            {
                return false;
            }

        }

        public static bool SendSms(string msg)
        {
            return true;
        }
    }

    public class VCode
    {
        public string code { get; set; }
    }

}
